var e = require;
var t = module;
var o = exports;
Object.defineProperty(o, "__esModule", {value: !0});
var n = e("BaseModuleUI"),
    a = e("NotifyEventType"),
    i = e("GlobalParams"),
    r = e("AssetsManager"),
    s = e("AudioManager"),
    l = e("CommonHelper"),
    c = e("PureHelper"),
    d = e("Game"),
    h = e("RoleSoldierInfo"),
    _ = e("AI_node"),
    u = e("node_team"),
    p = e("player_info_node"),
    m = e("player_node"),
    f = e("role_effects_info"),
    g = e("role_skill"),
    v = e("role_sound"),
    y = cc._decorator,
    S = y.ccclass,
    I = y.property,
    w = (function (e) {
        function t() {
            var t = (null !== e && e.apply(this, arguments)) || this;
            return (
                (t.role_skin = null),
                (t.attack_effect_skin = null),
                (t.be_hit_skin = null),
                (t.arrow_node = null),
                (t.arrowNodeType = ["role_3", "role_4"]),
                (t.role_move = !1),
                (t.moveDir = new cc.Vec2(0, 0)),
                (t.role_info = null),
                (t.is_AI = !1),
                (t.role_skill = null),
                (t.role_attack = !1),
                (t.player_info_node = null),
                (t.player_info = null),
                (t.match_game_index = 0),
                (t.skill_one_time = 0),
                (t.skill_two_time = 0),
                (t.role_rigidbody = null),
                (t.home_pos = null),
                (t.add_heal = null),
                (t.reduce_attack = !1),
                (t.role_death = !1),
                (t.have_blue_buff = !1),
                (t.have_red_buff = !1),
                (t.have_drager_buff = !1),
                (t.player_flash = !1),
                (t.one_double = !1),
                (t.two_doubel = !1),
                (t.for_speed = 0),
                (t.role_sound = null),
                t
            );
        }
        var o;
        return (
            __extends(t, e),
            (o = t),
            (t.prototype.showRoleInfo = function (e, t) {
                (this.is_AI = e),
                    (this.role_death = !1),
                    (this.node.getComponent(m.default).enabled = !this.is_AI),
                    (this.node.getComponent(_.default).enabled = this.is_AI),
                    (this.match_game_index = t),
                    (this.player_info = i.GlobalParams.MatchGamePlayer[t]),
                    (this.role_info = h.default.Role_info[this.player_info.role_id]),
                    (this.role_sound = this.node.getComponent(v.default));
            }),
            (t.prototype.setPlayerInfoNode = function (e) {
                this.player_info_node = e;
                var t = this.node.getPosition();
                this.player_info_node.setPosition(cc.v2(t.x + 12, t.y + 230)),
                    this.player_info_node.getComponent(p.default).InfoInit(this.match_game_index, this.node);
            }),
            (t.prototype.initView = function () {
                var e = this;
                (this.role_skin.node.zIndex = 4),
                    (this.be_hit_skin.node.active = !1),
                    (this.home_pos = this.node.getPosition()),
                    (this.add_heal = cc.instantiate(r.default.getInstance().getFightPrefab("role_effects"))),
                    (this.add_heal.active = !1),
                    this.add_heal.setParent(this.node),
                    (this.role_skill = this.node.getComponent(g.default)),
                    (this.attack_effect_skin.node.active = !1),
                    this.playRoleAnimation("battle_idle", !0),
                    this.updateTime(),
                    (this.role_rigidbody = this.node.getComponent(cc.RigidBody)),
                    this.is_AI || this.emitEvent(a.default.SEND_PLAYER_POS_INFO, this.node),
                    this.emitEvent(a.default.SEND_ROLE_SMALL_HEAD_POS, {
                        index: this.match_game_index,
                        pos: this.node.getPosition()
                    }),
                    this.role_skin.setCompleteListener(function (t, o) {
                        e.roleSkinCompleteListener(t, o);
                    });
            }),
            (t.prototype.addEvent = function () {
                this.attachEvent(a.default.SEND_GAME_OVER_INFO, this.gameOverAnime, this),
                    this.attachEvent(a.default.SEND_ROLE_ADD_BIG_DRAGON_BUFF, this.showRoleBeKill, this);
            }),
            (t.prototype.showRoleBeKill = function (e, t) {
                t % 2 == this.match_game_index % 2 && this.addRoleEffects(d.RoleEffectType.dragon_buff);
            }),
            (t.prototype.gameOverAnime = function () {
                this.match_game_index % 2 == i.GlobalParams.MatchMyIndex % 2
                    ? this.playRoleAnimation(i.GlobalParams.GamePlayerWin ? "victory" : "battle_idle", !0)
                    : this.playRoleAnimation(i.GlobalParams.GamePlayerWin ? "battle_idle" : "victory", !0);
            }),
            (t.prototype.updateTime = function () {
                var e = this;
                if (i.GlobalParams.GameStart && !this.role_death) {
                    if (this.player_flash) {
                        var t = this.node.getPosition().add(cc.v2(this.node.scaleX > 0 ? -1 : 1, 0).mul(300));
                        cc.tween(this.node)
                            .to(i.GlobalParams.GameUpdateTime, {position: cc.v3(t.x, t.y, 0)})
                            .call(function () {
                                e.role_rigidbody.syncPosition(!0), (e.player_flash = !1);
                            })
                            .start();
                    } else this.role_move && !this.role_attack && this.roleMove();
                    this.is_AI ||
                        (Math.abs(this.node.getPosition().x - this.home_pos.x) <= 180 &&
                        this.player_info_node.getComponent(p.default).getHpNotFull()
                            ? (this.add_heal.active ||
                                  ((this.add_heal.active = !0),
                                  this.add_heal.getComponent(f.default).showEffectInfo(d.RoleEffectType.home_heal)),
                              this.setRoleAddHp())
                            : (this.add_heal.active = !1));
                }
                this.scheduleOnce(function () {
                    e.updateTime();
                }, i.GlobalParams.GameUpdateTime);
            }),
            (t.prototype.roleMoveInfo = function (e) {
                i.GlobalParams.GameStart &&
                    ((this.moveDir = e),
                    this.role_move || this.role_attack || ((this.role_move = !0), this.playRoleAnimation("run", !0)));
            }),
            (t.prototype.roleStopMove = function () {
                this.role_move &&
                    !this.role_attack &&
                    (this.node.stopAllActions(), this.playRoleAnimation("battle_idle", !0)),
                    (this.role_move = !1);
            }),
            (t.prototype.roleCommonSkill = function () {
                this.roleSkillAnime("attack");
            }),
            (t.prototype.roleSpecialSkillOne = function () {
                this.skill_one_time <= 0 &&
                    (this.role_attack && "attack" == this.role_skin.animation && (this.role_attack = !1),
                    this.one_double ||
                        -1 == i.GlobalParams.MatchGamePlayer[this.match_game_index].equip_info.indexOf(15) ||
                        (this.one_double = !0),
                    this.roleSkillAnime("attack_skill1"));
            }),
            (t.prototype.roleSpecialSkillTwo = function () {
                this.skill_two_time <= 0 &&
                    (this.role_attack && "attack" == this.role_skin.animation && (this.role_attack = !1),
                    this.two_doubel ||
                        -1 == i.GlobalParams.MatchGamePlayer[this.match_game_index].equip_info.indexOf(29) ||
                        (this.two_doubel = !0),
                    this.roleSkillAnime("attack_skill2"));
            }),
            (t.prototype.AISpecialSkill = function () {
                this.skill_one_time <= 0 && this.player_info.skill_info[0] > 0
                    ? this.roleSpecialSkillOne()
                    : this.skill_two_time <= 0 && this.player_info.skill_info[1] > 0
                    ? this.roleSpecialSkillTwo()
                    : this.roleCommonSkill();
            }),
            (t.prototype.roleSkillAnime = function (e) {
                var t = this;
                if (!this.role_attack && !this.role_death) {
                    "attack" == e
                        ? (this.role_sound.playAttack(), this.playAttackAudio())
                        : "attack_skill1" == e
                        ? this.role_sound.playSkillOne()
                        : "attack_skill2" == e && this.role_sound.playSkillTow(),
                        (this.role_attack = !0),
                        (this.attack_effect_skin.node.active = !0);
                    var o = this.role_skin.setAnimation(0, e, !0);
                    this.attack_effect_skin.setAnimation(0, e, !1);
                    var n =
                        i.GlobalParams.GamePlayerInfo[this.match_game_index].attack_speed -
                        i.GlobalParams.BuyEquipInfo[this.match_game_index].attack_speed;
                    2 == i.GlobalParams.ChangeGameMode && (n = 0.5),
                        (n = n < 0.6 ? 0.6 : n),
                        (this.role_skin.timeScale = n),
                        (this.attack_effect_skin.timeScale = n),
                        this.role_skin.setTrackEventListener(o, function () {
                            t.role_skill.roleCommonSkill(!1, e),
                                t.role_skill.roleCommonSkill(!0, e),
                                (t.role_skin.timeScale = 1),
                                (t.attack_effect_skin.timeScale = 1),
                                "attack" == e &&
                                    t.arrow_node &&
                                    (t.arrow_node.setPosition(cc.v2(-80, 140)),
                                    (t.arrow_node.active = !0),
                                    4 == t.player_info.role_id &&
                                        t.arrow_node.getComponent(sp.Skeleton).setAnimation(0, "zd", !0),
                                    cc
                                        .tween(t.arrow_node)
                                        .by(0.3, {position: cc.v3(-500, 0, 0)})
                                        .call(function () {
                                            4 == t.player_info.role_id
                                                ? (t.arrow_node.getComponent(sp.Skeleton).setAnimation(0, "zd_bz", !1),
                                                  t.arrow_node
                                                      .getComponent(sp.Skeleton)
                                                      .setCompleteListener(function () {
                                                          t.arrow_node
                                                              .getComponent(sp.Skeleton)
                                                              .setCompleteListener(null),
                                                              t.arrow_node.setPosition(cc.v2(-80, 140)),
                                                              (t.arrow_node.active = !1);
                                                      }))
                                                : (t.arrow_node.setPosition(cc.v2(-80, 140)),
                                                  (t.arrow_node.active = !1));
                                        })
                                        .start());
                        });
                }
            }),
            (t.prototype.roleSkinCompleteListener = function (e) {
                var t = this,
                    o = e.animation ? e.animation.name : "";
                -1 != ["attack", "attack_skill1", "attack_skill2"].indexOf(o) &&
                    (this.role_skill.roleCommonSkill(!1, o),
                    this.role_skin.clearTracks(),
                    this.role_move ? this.playRoleAnimation("run", !0) : this.playRoleAnimation("battle_idle", !0),
                    (this.attack_effect_skin.node.active = !1),
                    this.scheduleOnce(function () {
                        t.role_attack = !1;
                    }, 0.2),
                    this.skillCoolingTime(o)),
                    "death" == o && this.node.destroy();
            }),
            (t.prototype.roleMove = function () {
                var e = this;
                0 != this.moveDir.x && (this.node.scaleX = Math.abs(this.node.scaleX) * (this.moveDir.x < 0 ? 1 : -1));
                var t =
                    i.GlobalParams.GamePlayerInfo[this.match_game_index].move_speed +
                    i.GlobalParams.BuyEquipInfo[this.match_game_index].move_speed;
                this.for_speed > 0 && (t = Math.ceil(t * (1 - this.for_speed / 100)));
                var o = this.node.getPosition().add(this.moveDir.mul(t));
                cc
                    .tween(this.node)
                    .to(i.GlobalParams.GameUpdateTime, {position: cc.v3(o.x, o.y, 0)})
                    .call(function () {
                        e.is_AI || e.emitEvent(a.default.SEND_PLAYER_POS_INFO, e.node),
                            e.emitEvent(a.default.SEND_ROLE_SMALL_HEAD_POS, {
                                index: e.match_game_index,
                                pos: e.node.getPosition()
                            }),
                            e.role_rigidbody.syncPosition(!0);
                    })
                    .start(),
                    cc
                        .tween(this.player_info_node)
                        .to(i.GlobalParams.GameUpdateTime, {position: cc.v3(o.x + 12, o.y + 230, 0)})
                        .start(),
                    this.match_game_index == i.GlobalParams.MatchMyIndex && this.role_sound.playRun();
            }),
            (t.prototype.getRoleSkillAttack = function (e) {
                var t = 0,
                    o = i.GlobalParams.GamePlayerInfo[this.match_game_index];
                if (!this.player_info_node) return 0;
                switch (e) {
                    case 1:
                        if (
                            ((t = o.attack),
                            (t += Math.ceil(t * (i.GlobalParams.BuyEquipInfo[this.match_game_index].add_attack / 100))),
                            i.GlobalParams.BuyEquipInfo[this.match_game_index].attack_hp > 0 &&
                                cc.isValid(this.player_info_node, !0))
                        ) {
                            var n = i.GlobalParams.BuyEquipInfo[this.match_game_index].attack_hp / 100;
                            this.player_info_node.getComponent(p.default).roleSkillAddHp(n);
                        }
                        this.one_double
                            ? ((t += t), (this.one_double = !1))
                            : this.two_doubel && ((t += 1.5 * t), (this.two_doubel = !1));
                        break;
                    case 2:
                        (t =
                            o.skill_1 +
                            o.attack * this.role_info.S1_attack_add +
                            i.GlobalParams.BuyEquipInfo[this.match_game_index].skill_1),
                            (t += Math.ceil(t * (i.GlobalParams.BuyEquipInfo[this.match_game_index].skill_add / 100)));
                        break;
                    case 3:
                        (t =
                            o.skill_2 +
                            o.attack * this.role_info.S2_attack_add +
                            i.GlobalParams.BuyEquipInfo[this.match_game_index].skill_2),
                            (t += Math.ceil(t * (i.GlobalParams.BuyEquipInfo[this.match_game_index].skill_add / 100)));
                }
                if (
                    i.GlobalParams.BuyEquipInfo[this.match_game_index].suck_blood > 0 &&
                    cc.isValid(this.player_info_node, !0)
                ) {
                    var a = Math.ceil(t * (i.GlobalParams.BuyEquipInfo[this.match_game_index].suck_blood / 100));
                    this.player_info_node.getComponent(p.default).setRoleAddHp(a);
                }
                return (
                    (t += i.GlobalParams.BuyEquipInfo[this.match_game_index].attack),
                    this.reduce_attack && (t *= 0.5),
                    this.have_red_buff && (t += 0.1 * t),
                    l.default.getRandomInt(1, 100) <= i.GlobalParams.BuyEquipInfo[this.match_game_index].crit &&
                        (t *= 2),
                    t.toFixed()
                );
            }),
            (t.prototype.showRoleDeath = function () {
                (this.role_death = !0),
                    this.node.stopAllActions(),
                    this.role_sound.playDie(),
                    this.playRoleAnimation("death", !1);
            }),
            (t.prototype.getRoleHpPercent = function () {
                return this.player_info_node.getComponent(p.default).getRoleHpPercent();
            }),
            (t.prototype.setRoleAddHp = function () {
                this.player_info_node.getComponent(p.default).setRoleAddHp(50);
            }),
            (t.prototype.roleSkillAddHp = function (e) {
                this.player_info_node.getComponent(p.default).roleSkillAddHp(e);
            }),
            (t.prototype.roleBeHit = function (e, t) {
                var o = this;
                if (!this.role_death) {
                    this.have_drager_buff && (e = Math.floor(0.5 * e));
                    var n = i.GlobalParams.BuyEquipInfo[this.match_game_index].be_hit;
                    (n = n > 50 ? 50 : n),
                        (e = Math.ceil(e * (1 - n / 100))),
                        this.player_info_node.getComponent(p.default).roleBeHit(e, t),
                        (this.be_hit_skin.node.active = !0),
                        this.be_hit_skin.setAnimation(0, "受击特效", !1),
                        s.default.getInstance().playFx("hit2"),
                        this.be_hit_skin.setCompleteListener(function () {
                            o.be_hit_skin.node.active = !1;
                        });
                }
            }),
            (t.prototype.skillCoolingTime = function (e) {
                var t = this;
                "attack_skill1" == e
                    ? ((this.skill_one_time =
                          i.GlobalParams.GamePlayerInfo[this.match_game_index].cool_1 -
                          i.GlobalParams.BuyEquipInfo[this.match_game_index].cool_1),
                      this.have_blue_buff && (this.skill_one_time -= Math.ceil(0.1 * this.skill_one_time)),
                      (this.skill_one_time = this.skill_one_time < 3 ? 3 : this.skill_one_time),
                      (this.skill_one_time = Number(this.skill_one_time.toFixed(1))),
                      2 == i.GlobalParams.ChangeGameMode && (this.skill_one_time = 1),
                      this.scheduleOnce(function () {
                          t.skill_one_time = 0;
                      }, this.skill_one_time),
                      this.is_AI ||
                          this.emitEvent(a.default.SEND_PLAYER_SKILL_COOLING_TIME, {
                              type: 1,
                              time: this.skill_one_time
                          }))
                    : "attack_skill2" == e &&
                      ((this.skill_two_time =
                          i.GlobalParams.GamePlayerInfo[this.match_game_index].cool_2 -
                          i.GlobalParams.BuyEquipInfo[this.match_game_index].cool_2),
                      this.have_blue_buff && (this.skill_two_time -= Math.ceil(0.1 * this.skill_two_time)),
                      (this.skill_two_time = this.skill_two_time < 5 ? 5 : this.skill_two_time),
                      (this.skill_two_time = Number(this.skill_two_time.toFixed(1))),
                      2 == i.GlobalParams.ChangeGameMode && (this.skill_two_time = 4),
                      this.scheduleOnce(function () {
                          t.skill_two_time = 0;
                      }, this.skill_two_time),
                      this.is_AI ||
                          this.emitEvent(a.default.SEND_PLAYER_SKILL_COOLING_TIME, {
                              type: 2,
                              time: this.skill_two_time
                          }));
            }),
            (t.prototype.showSprintSkill = function () {
                var e = this;
                (i.GlobalParams.GamePlayerInfo[this.match_game_index].move_speed += 20),
                    this.addRoleEffects(d.RoleEffectType.sprint),
                    this.scheduleOnce(function () {
                        i.GlobalParams.GamePlayerInfo[e.match_game_index].move_speed -= 20;
                    }, 5);
            }),
            (t.prototype.showAddHpSkill = function () {
                this.player_info_node.getComponent(p.default).playerSkillAddHp(),
                    this.addRoleEffects(d.RoleEffectType.heal);
            }),
            (t.prototype.showLightSkill = function () {
                var e = this.eachSoliderInfo();
                e && e.getComponent(o).player_info_node.getComponent(p.default).playerBeLight(this.match_game_index);
            }),
            (t.prototype.showWeaknessSkill = function () {
                var e = this.eachSoliderInfo();
                e && (e.getComponent(o).beWeaknessHit(), e.getComponent(o).addRoleEffects(d.RoleEffectType.clock));
            }),
            (t.prototype.showKillSkill = function () {
                for (
                    var e = this.node.getComponent(u.default).getTeamInfo(), t = 0, n = this.node.parent.children;
                    t < n.length;
                    t++
                ) {
                    var a = n[t],
                        i = a.getComponent(u.default).getTeamInfo();
                    cc.isValid(a, !0) &&
                        "role" == a.group &&
                        i != e &&
                        i != d.TeamInfo.rest_team &&
                        Math.abs(c.default.Distance(this.node.getPosition(), a.getPosition())) < 300 &&
                        a.getComponent(o).roleBeHit(this.getRoleSkillAttack(1), this.match_game_index);
                }
                this.addRoleEffects(d.RoleEffectType.kill);
            }),
            (t.prototype.showFlashSkill = function () {
                var e = this;
                if (((this.player_flash = !0), !this.role_move)) {
                    var t = this.node.getPosition().add(cc.v2(this.node.scaleX > 0 ? -1 : 1, 0).mul(300));
                    cc.tween(this.node)
                        .to(i.GlobalParams.GameUpdateTime, {position: cc.v3(t.x, t.y, 0)})
                        .call(function () {
                            e.role_rigidbody.syncPosition(!0), (e.player_flash = !1);
                        })
                        .start();
                }
            }),
            (t.prototype.beWeaknessHit = function () {
                var e = this;
                (this.reduce_attack = !0),
                    this.scheduleOnce(function () {
                        e.reduce_attack = !1;
                    }, 5);
            }),
            (t.prototype.eachSoliderInfo = function () {
                for (
                    var e = 9999,
                        t = null,
                        o = this.node.getComponent(u.default).getTeamInfo(),
                        n = 0,
                        a = this.node.parent.children;
                    n < a.length;
                    n++
                ) {
                    var i = a[n],
                        r = i.getComponent(u.default).getTeamInfo();
                    if (cc.isValid(i, !0) && "role" == i.group && r != o && r != d.TeamInfo.rest_team) {
                        var s = Math.abs(c.default.Distance(this.node.getPosition(), i.getPosition()));
                        if (s > 300) continue;
                        s < e && ((e = s), (t = i));
                    }
                }
                return t;
            }),
            (t.prototype.playRoleAnimation = function (e, t) {
                "death" != this.role_skin.animation && this.role_skin.setAnimation(0, e, t);
            }),
            (t.prototype.addRoleEffects = function (e) {
                var t = this;
                e == d.RoleEffectType.red_buff
                    ? ((this.have_red_buff = !0),
                      this.scheduleOnce(function () {
                          t.have_red_buff = !1;
                      }, 40))
                    : e == d.RoleEffectType.blue_buff
                    ? ((this.have_blue_buff = !0),
                      this.scheduleOnce(function () {
                          t.have_blue_buff = !1;
                      }, 40))
                    : e == d.RoleEffectType.dragon_buff &&
                      ((this.have_drager_buff = !0),
                      this.scheduleOnce(function () {
                          t.have_drager_buff = !1;
                      }, 60));
                var o = cc.instantiate(r.default.getInstance().getFightPrefab("role_effects"));
                o.setParent(this.node), o.getComponent(f.default).showEffectInfo(e);
            }),
            (t.prototype.getEquipForSpeed = function () {
                return i.GlobalParams.BuyEquipInfo[this.match_game_index].for_speed;
            }),
            (t.prototype.setForSpeed = function (e) {
                var t = this;
                0 == this.for_speed &&
                    ((this.for_speed = e),
                    this.scheduleOnce(function () {
                        t.for_speed = 0;
                    }, 5));
            }),
            (t.prototype.playAttackAudio = function () {
                if (this.myDisRound()) {
                    var e = this.player_info.role_id;
                    -1 != [2, 3, 8, 11, 12].indexOf(e) &&
                        s.default.getInstance().playFx("girl_01_0" + l.default.getRandomInt(1, 3)),
                        -1 != [0, 4, 5, 6].indexOf(e) &&
                            s.default.getInstance().playFx("girl02_0" + l.default.getRandomInt(1, 3)),
                        -1 != [1, 7, 10].indexOf(e) &&
                            s.default.getInstance().playFx("man01_0" + l.default.getRandomInt(1, 3)),
                        -1 != [9].indexOf(e) &&
                            s.default.getInstance().playFx("man01_0" + l.default.getRandomInt(1, 3));
                }
            }),
            (t.prototype.myDisRound = function () {
                var e = !1,
                    t = this.node.parent.getChildByName("role_team_" + i.GlobalParams.MatchMyIndex);
                return (
                    cc.isValid(t, !0) &&
                        Math.abs(c.default.Distance(this.node.getPosition(), t.getPosition())) < 600 &&
                        (e = !0),
                    e
                );
            }),
            __decorate([I(sp.Skeleton)], t.prototype, "role_skin", void 0),
            __decorate([I(sp.Skeleton)], t.prototype, "attack_effect_skin", void 0),
            __decorate([I(sp.Skeleton)], t.prototype, "be_hit_skin", void 0),
            __decorate(
                [
                    I({
                        type: cc.Node,
                        visible: function () {
                            return -1 != this.arrowNodeType.indexOf(this.node.name);
                        }
                    })
                ],
                t.prototype,
                "arrow_node",
                void 0
            ),
            (o = __decorate([S], t))
        );
    })(n.default);
o.default = w;
